package com.example.diagnodroid.connexion;

import android.app.AlertDialog;
import android.app.Service;
import android.bluetooth.BluetoothAdapter;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.os.IBinder;
import android.provider.Settings;
import android.util.Log;

public class BluetoothTracker extends Service {

	private final Context mContext;
	
	// flag for bluetooth status
	boolean isBluetoothEnabled = false;

	// Declaring a bluetooth Manager
	protected BluetoothAdapter bluetoothAdapter;
	
	

	public BluetoothTracker(Context context) {
		this.mContext = context;
		getBluetoothInfos();
	}

	public void getBluetoothInfos() {
		
		bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();;

			// getting Bluetooth status
			isBluetoothEnabled = bluetoothAdapter.isEnabled();

			// if Bluetooth Enabled 
			if (isBluetoothEnabled) {
					
			} else {
				this.showSettingsAlert(); 
			}			

	}


	/**
	 * Function to show settings alert dialog On pressing Settings button will
	 * lauch Settings Options
	 * */
	public void showSettingsAlert() {
		AlertDialog.Builder alertDialog = new AlertDialog.Builder(mContext);

		// Setting Dialog Title
		alertDialog.setTitle("Bluetooth is settings");

		// Setting Dialog Message
		alertDialog
				.setMessage("Bluetooth is not enabled. Do you want to go to settings menu?");

		// On pressing Settings button
		alertDialog.setPositiveButton("Settings",
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {
						Intent intent = new Intent(Settings.ACTION_BLUETOOTH_SETTINGS);
						mContext.startActivity(intent);
					}
				});

		// on pressing cancel button
		alertDialog.setNegativeButton("Cancel",
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {
						dialog.cancel();
					}
				});

		// Showing Alert Message
		alertDialog.show();
	}

	@Override
	public IBinder onBind(Intent intent) {
		// TODO Auto-generated method stub
		return null;
	}

}
